#include "remotefiledownloader.h"


RemoteFileDownloader::RemoteFileDownloader(const QUrl& fileToDownload,
                                           const QDir& directoryOfDownload,
                                           const QString& fileName):
    Downloader(fileToDownload),
    _directoryOfDownload(directoryOfDownload),
    _fileName(fileName)
{
}

void RemoteFileDownloader::replyFinished()
{
    QFile saveFile(_directoryOfDownload.filePath(_fileName));

    if ( saveFile.exists() )
        saveFile.remove();

    if ( !saveFile.open(QIODevice::WriteOnly) )
        return;

    saveFile.write(_reply->readAll());

    emit downloadFinished();    
}
